package com.example.memosystem.service.impl;

import com.example.memosystem.mapper.CategoryMapper;
import com.example.memosystem.model.Category;
import com.example.memosystem.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {
    
    @Autowired
    private CategoryMapper categoryMapper;
    
    @Override
    public boolean addCategory(Category category) {
        Date now = new Date();
        category.setCreateTime(now);
        category.setUpdateTime(now);
        return categoryMapper.insertCategory(category) > 0;
    }
    
    @Override
    public boolean updateCategory(Category category) {
        category.setUpdateTime(new Date());
        return categoryMapper.updateCategory(category) > 0;
    }
    
    @Override
    public boolean deleteCategory(Integer id, Integer userId) {
        return categoryMapper.deleteCategory(id, userId) > 0;
    }
    
    @Override
    public Category findById(Integer id, Integer userId) {
        return categoryMapper.findById(id, userId);
    }
    
    @Override
    public List<Category> findAllByUserId(Integer userId) {
        return categoryMapper.findAllByUserId(userId);
    }
}